package cn.lwx.javaweb.web.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.lwx.javaweb.utils.StudentUtils;
import cn.lwx.javaweb.utils.UserUtils;

/**
 * 用户信息模板类
 *
 * @author lwx
 * @date 2021-05-08
 */
@WebServlet("/user/update")
public class UserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");

		String username = request.getParameter("username");
		String password = request.getParameter("password");


		HttpSession session = request.getSession();
		session.setAttribute("username",username);

		int n = UserUtils.update(password, username);

		if(n==1) {
			System.out.println("修改成功");
            response.sendRedirect(request.getContextPath() + "/stu/list");
		}else {
			System.out.println("修改失败");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
